﻿
// This file implements the TableControl, TableControlRow, and RecordControl classes for the 
// SearchEditGasolineraXTipoGasolinera.aspx page.  The Row or RecordControl classes are the 
// ideal place to add code customizations. For example, you can override the LoadData, 
// CreateWhereClause, DataBind, SaveData, GetUIData, and Validate methods.

#region "Using statements"    

using Microsoft.VisualBasic;
using BaseClasses.Web.UI.WebControls;
using System;
using System.Collections;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseClasses;
using BaseClasses.Data;
using BaseClasses.Utils;
using ReportTools.ReportCreator;
using ReportTools.Shared;

        
using EnGasAdoAPP.Business;
using EnGasAdoAPP.Data;
using EnGasAdoAPP.UI;
using EnGasAdoAPP;
		

#endregion

  
namespace EnGasAdoAPP.UI.Controls.SearchEditGasolineraXTipoGasolinera
{
  

#region "Section 1: Place your customizations here."

    
public class GasolineraXTipoGasolineraRecordControl : BaseGasolineraXTipoGasolineraRecordControl
{
      
        // The BaseGasolineraXTipoGasolineraRecordControl implements the LoadData, DataBind and other
        // methods to load and display the data in a table control.

        // This is the ideal place to add your code customizations. For example, you can override the LoadData, 
        // CreateWhereClause, DataBind, SaveData, GetUIData, and Validate methods.
        
}

  

#endregion

  

#region "Section 2: Do not modify this section."
    
    
// Base class for the GasolineraXTipoGasolineraRecordControl control on the SearchEditGasolineraXTipoGasolinera page.
// Do not modify this class. Instead override any method in GasolineraXTipoGasolineraRecordControl.
public class BaseGasolineraXTipoGasolineraRecordControl : EnGasAdoAPP.UI.BaseApplicationRecordControl
{
        public BaseGasolineraXTipoGasolineraRecordControl()
        {
            this.Init += Control_Init;
            this.Load += Control_Load;
            this.PreRender += Control_PreRender;
            this.EvaluateFormulaDelegate = new DataSource.EvaluateFormulaDelegate(this.EvaluateFormula);
        }

        // To customize, override this method in GasolineraXTipoGasolineraRecordControl.
        protected virtual void Control_Init(object sender, System.EventArgs e)
        {
        
            
            
            // Setup the filter and search events.
        
            this.ID_GasolineraFilter.SelectedIndexChanged += new EventHandler(ID_GasolineraFilter_SelectedIndexChanged);
            this.ID_Tipo_ServicioFilter.SelectedIndexChanged += new EventHandler(ID_Tipo_ServicioFilter_SelectedIndexChanged);
            if (!this.Page.IsPostBack)
            {
                string initialVal = "";
                if  (this.InSession(this.ID_GasolineraFilter)) 				
                    initialVal = this.GetFromSession(this.ID_GasolineraFilter);
                
                else
                    
                    initialVal = EvaluateFormula("URL(\"ID_Gasolinera\")");
                
                if (initialVal != null && initialVal != "")		
                {
                        
                    string[] ID_GasolineraFilteritemListFromSession = initialVal.Split(',');
                    int index = 0;
                    foreach (string item in ID_GasolineraFilteritemListFromSession)
                    {
                        if (index == 0 && item.ToString().Equals(""))
                        {
                            // do nothing
                        }
                        else
                        {
                            this.ID_GasolineraFilter.Items.Add(item);
                            this.ID_GasolineraFilter.Items[index].Selected = true;
                            index += 1;
                        }
                    }
                    foreach (ListItem listItem in this.ID_GasolineraFilter.Items)
                    {
                        listItem.Selected = true;
                    }
                        
                    }
            }
            if (!this.Page.IsPostBack)
            {
                string initialVal = "";
                if  (this.InSession(this.ID_Tipo_ServicioFilter)) 				
                    initialVal = this.GetFromSession(this.ID_Tipo_ServicioFilter);
                
                else
                    
                    initialVal = EvaluateFormula("URL(\"ID_Tipo_Servicio\")");
                
                if (initialVal != null && initialVal != "")		
                {
                        
                    string[] ID_Tipo_ServicioFilteritemListFromSession = initialVal.Split(',');
                    int index = 0;
                    foreach (string item in ID_Tipo_ServicioFilteritemListFromSession)
                    {
                        if (index == 0 && item.ToString().Equals(""))
                        {
                            // do nothing
                        }
                        else
                        {
                            this.ID_Tipo_ServicioFilter.Items.Add(item);
                            this.ID_Tipo_ServicioFilter.Items[index].Selected = true;
                            index += 1;
                        }
                    }
                    foreach (ListItem listItem in this.ID_Tipo_ServicioFilter.Items)
                    {
                        listItem.Selected = true;
                    }
                        
                    }
            }
            // Control Initializations.
            // Initialize the table's current sort order.
          
            if (this.InSession(this, "Order_By")) {
                this.CurrentSortOrder = OrderBy.FromXmlString(this.GetFromSession(this, "Order_By", null));
            } else {
                this.CurrentSortOrder = new OrderBy(true, false);
                          }
            this.PageIndex = Convert.ToInt32(this.GetFromSession(this, "Page_Index", "0"));
                
            this.ClearControlsFromSession();
        }

        // To customize, override this method in GasolineraXTipoGasolineraRecordControl.
        protected virtual void Control_Load(object sender, System.EventArgs e)
        {
        
            SaveControlsToSession_Ajax();
        
              // Show confirmation message on Click
              this.GasolineraXTipoGasolineraDeleteButton.Attributes.Add("onClick", "return (confirm('" + ((BaseApplicationPage)this.Page).GetResourceValue("DeleteConfirm", "EnGasAdoAPP") + "'));");
            // Setup the pagination events.	  
         
              this.GasolineraXTipoGasolineraPagination.FirstPage.Click += new ImageClickEventHandler(GasolineraXTipoGasolineraPagination_FirstPage_Click);
        
              this.GasolineraXTipoGasolineraPagination.LastPage.Click += new ImageClickEventHandler(GasolineraXTipoGasolineraPagination_LastPage_Click);
        
              this.GasolineraXTipoGasolineraPagination.NextPage.Click += new ImageClickEventHandler(GasolineraXTipoGasolineraPagination_NextPage_Click);
        
              this.GasolineraXTipoGasolineraPagination.PageSizeButton.Click += GasolineraXTipoGasolineraPagination_PageSizeButton_Click;
            
              this.GasolineraXTipoGasolineraPagination.PreviousPage.Click += new ImageClickEventHandler(GasolineraXTipoGasolineraPagination_PreviousPage_Click);
           
        
            // Register the event handlers.
          
              this.GasolineraXTipoGasolineraCopyButton.Click += new ImageClickEventHandler(GasolineraXTipoGasolineraCopyButton_Click);
        
              this.GasolineraXTipoGasolineraDeleteButton.Click += new ImageClickEventHandler(GasolineraXTipoGasolineraDeleteButton_Click);
        
              this.GasolineraXTipoGasolineraNewButton.Click += new ImageClickEventHandler(GasolineraXTipoGasolineraNewButton_Click);
        
              this.GasolineraXTipoGasolineraSaveButton.Click += new ImageClickEventHandler(GasolineraXTipoGasolineraSaveButton_Click);
        
              this.GasolineraXTipoGasolineraSaveButton.Attributes.Add("onclick", "SubmitHRefOnce(this, \"" + this.Page.GetResourceValue("Txt:SaveRecord", "EnGasAdoAPP") + "\");");
        
             
                this.ID_GasolineraAddRecordLink.PostBackUrl = "../Gasolinera/AddGasolinera.aspx" + "?Target=" + this.ID_Gasolinera.ClientID + "&DFKA=" + HttpUtility.UrlEncode("Descripcion")
                  ;
              this.ID_GasolineraAddRecordLink.Attributes["onClick"] = "window.open('" + this.ID_GasolineraAddRecordLink.PostBackUrl + "','_blank', 'width=900, height=700, resizable, scrollbars, modal=yes'); return false;";
          
             
                this.ID_Tipo_ServicioAddRecordLink.PostBackUrl = "../Tipo_Servicio/AddTipo_Servicio.aspx" + "?Target=" + this.ID_Tipo_Servicio.ClientID + "&DFKA=" + HttpUtility.UrlEncode("Descripcion")
                  ;
              this.ID_Tipo_ServicioAddRecordLink.Attributes["onClick"] = "window.open('" + this.ID_Tipo_ServicioAddRecordLink.PostBackUrl + "','_blank', 'width=900, height=700, resizable, scrollbars, modal=yes'); return false;";
          
              this.GasolineraXTipoGasolineraFilterButton.Button.Click += GasolineraXTipoGasolineraFilterButton_Click;
        
              this.ID_Gasolinera.SelectedIndexChanged += ID_Gasolinera_SelectedIndexChanged;
            
              this.ID_Tipo_Servicio.SelectedIndexChanged += ID_Tipo_Servicio_SelectedIndexChanged;
            
        }

        public virtual void LoadData()  
        {
            // Load the data from the database into the DataSource GasolineraXTipoGasolinera record.
            // It is better to make changes to functions called by LoadData such as
            // CreateWhereClause, rather than making changes here.
            
        
            // This is the first time a record is being retrieved from the database.
            // So create a Where Clause based on the staic Where clause specified
            // on the Query wizard and the dynamic part specified by the end user
            // on the search and filter controls (if any).
            
            WhereClause wc = this.CreateWhereClause();
            
            System.Web.UI.WebControls.Panel Panel = (System.Web.UI.WebControls.Panel)MiscUtils.FindControlRecursively(this, "GasolineraXTipoGasolineraRecordControlPanel");
            if (Panel != null){
                Panel.Visible = true;
            }
            
            // If there is no Where clause, then simply create a new, blank record.
            
            if (wc == null || !(wc.RunQuery)) {
                this.DataSource = new GasolineraXTipoGasolineraRecord();
            
                if (Panel != null){
                    Panel.Visible = false;
                }
              
                return;
            }
          
            CompoundFilter filterJoin = CreateCompoundJoinFilter();     
            this.TotalPages = GasolineraXTipoGasolineraTable.GetRecordCount(filterJoin, wc);
            if (this.DisplayLastPage) {
                this.PageIndex = this.TotalPages - 1;
            }
            // Retrieve the record from the database.  It is possible
            
            OrderBy orderBy = CreateOrderBy();
            GasolineraXTipoGasolineraRecord[] recList = GasolineraXTipoGasolineraTable.GetRecords(filterJoin, wc, orderBy, BaseTable.MIN_PAGE_NUMBER, this.TotalPages);
            if (recList.Length == 0) {
                // There is no data for this Where clause.
                this.PageIndex = 0;
                this.DataSource = new GasolineraXTipoGasolineraRecord();
                
                this.RecordUniqueId = null;
                if (Panel != null){
                    Panel.Visible = false;
                }
                return;
            }
            else if (this.PageIndex >= recList.Length){
                this.PageIndex = recList.Length -1;
            }
            else if (this.PageIndex < 0){
                this.PageIndex = 0;
            }
                  
            // Set DataSource based on record retrieved from the database.
            this.DataSource = GasolineraXTipoGasolineraTable.GetRecord(recList[this.PageIndex].GetID().ToXmlString(), true);
                  
        }

        public override void DataBind()
        {
            // The DataBind method binds the user interface controls to the values
            // from the database record.  To do this, it calls the Set methods for 
            // each of the field displayed on the webpage.  It is better to make 
            // changes in the Set methods, rather than making changes here.
            
            base.DataBind();
            
            // Make sure that the DataSource is initialized.
            
            if (this.DataSource == null) {
                return;
            }
              
    
            // LoadData for DataSource for chart and report if they exist
          
            // Setup the pagination controls.
            BindPaginationControls();
        

            // Call the Set methods for each controls on the panel
        
                
                
                
                
                
                
                
                SetID_Gasolinera();
                
                SetID_GasolineraFilter();
                SetID_GasolineraLabel();
                SetID_GasolineraLabel1();
                SetID_Tipo_Servicio();
                
                SetID_Tipo_ServicioFilter();
                SetID_Tipo_ServicioLabel();
                SetID_Tipo_ServicioLabel1();

      

            this.IsNewRecord = true;
          
            if (this.DataSource.IsCreated) {
                this.IsNewRecord = false;
              
                this.RecordUniqueId = this.DataSource.GetID().ToXmlString();
            }
          

            // Now load data for each record and table child UI controls.
            // Ordering is important because child controls get 
            // their parent ids from their parent UI controls.
            bool shouldResetControl = false;
            if (shouldResetControl) { }; // prototype usage to void compiler warnings
            
        }

        
        public virtual void SetID_Gasolinera()
        {
            
            
            // Set the ID_Gasolinera DropDownList on the webpage with value from the
            // GasolineraXTipoGasolinera database record.
            
            // this.DataSource is the GasolineraXTipoGasolinera record retrieved from the database.
            // this.ID_Gasolinera is the ASP:DropDownList on the webpage.
            
            // You can modify this method directly, or replace it with a call to
            //     base.SetID_Gasolinera();
            // and add your own custom code before or after the call to the base function.

            
            if (this.DataSource != null && this.DataSource.ID_GasolineraSpecified)
            {
                            
                // If the ID_Gasolinera is non-NULL, then format the value.
                // The Format method will return the Display Foreign Key As (DFKA) value
                this.PopulateID_GasolineraDropDownList(this.DataSource.ID_Gasolinera.ToString(), 100);
                
            }
            else
            {
                
                // ID_Gasolinera is NULL in the database, so use the Default Value.  
                // Default Value could also be NULL.
                if (this.DataSource != null && this.DataSource.IsCreated)
                    this.PopulateID_GasolineraDropDownList(null, 100);
                else
                    this.PopulateID_GasolineraDropDownList(GasolineraXTipoGasolineraTable.ID_Gasolinera.DefaultValue, 100);
                				
            }			
                     
        }
                
        public virtual void SetID_Tipo_Servicio()
        {
            
            
            // Set the ID_Tipo_Servicio DropDownList on the webpage with value from the
            // GasolineraXTipoGasolinera database record.
            
            // this.DataSource is the GasolineraXTipoGasolinera record retrieved from the database.
            // this.ID_Tipo_Servicio is the ASP:DropDownList on the webpage.
            
            // You can modify this method directly, or replace it with a call to
            //     base.SetID_Tipo_Servicio();
            // and add your own custom code before or after the call to the base function.

            
            if (this.DataSource != null && this.DataSource.ID_Tipo_ServicioSpecified)
            {
                            
                // If the ID_Tipo_Servicio is non-NULL, then format the value.
                // The Format method will return the Display Foreign Key As (DFKA) value
                this.PopulateID_Tipo_ServicioDropDownList(this.DataSource.ID_Tipo_Servicio.ToString(), 100);
                
            }
            else
            {
                
                // ID_Tipo_Servicio is NULL in the database, so use the Default Value.  
                // Default Value could also be NULL.
                if (this.DataSource != null && this.DataSource.IsCreated)
                    this.PopulateID_Tipo_ServicioDropDownList(null, 100);
                else
                    this.PopulateID_Tipo_ServicioDropDownList(GasolineraXTipoGasolineraTable.ID_Tipo_Servicio.DefaultValue, 100);
                				
            }			
                     
        }
                
        public virtual void SetID_GasolineraLabel()
                  {
                  
                    
        }
                
        public virtual void SetID_GasolineraLabel1()
                  {
                  
                    
        }
                
        public virtual void SetID_Tipo_ServicioLabel()
                  {
                  
                    
        }
                
        public virtual void SetID_Tipo_ServicioLabel1()
                  {
                  
                    
        }
                
        public BaseClasses.Data.DataSource.EvaluateFormulaDelegate EvaluateFormulaDelegate;

        public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate, string format, System.Collections.Generic.IDictionary<string, object> variables, bool includeDS, FormulaEvaluator e)
        {
            if (e == null)
                e = new FormulaEvaluator();

            e.Variables.Clear();
            // add variables for formula evaluation
            if (variables != null)
            {
                System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<string, object>> enumerator = variables.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    e.Variables.Add(enumerator.Current.Key, enumerator.Current.Value);
                }
            }
            
            
            if (includeDS)
            {
                
            }
            
            // All variables referred to in the formula are expected to be
            // properties of the DataSource.  For example, referring to
            // UnitPrice as a variable will refer to DataSource.UnitPrice
            if (dataSourceForEvaluate == null)
                e.DataSource = this.DataSource;
            else
                e.DataSource = dataSourceForEvaluate;

            // Define the calling control.  This is used to add other 
            // related table and record controls as variables.
            e.CallingControl = this;

            object resultObj = e.Evaluate(formula);
            if (resultObj == null)
                return "";
            
            if ( !string.IsNullOrEmpty(format) && (string.IsNullOrEmpty(formula) || formula.IndexOf("Format(") < 0) )
                return FormulaUtils.Format(resultObj, format);
            else
                return resultObj.ToString();
        }
                
        public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate, string format, System.Collections.Generic.IDictionary<string, object> variables, bool includeDS)
        {
          return EvaluateFormula(formula, dataSourceForEvaluate, format, variables, includeDS, null);
        }

        public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate, string format, System.Collections.Generic.IDictionary<string, object> variables)
        {
          return EvaluateFormula(formula, dataSourceForEvaluate, format, variables, true, null);
        }

        public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate, string format)
        {
          return this.EvaluateFormula(formula, dataSourceForEvaluate, format, null, true, null);
        }

        public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate, System.Collections.Generic.IDictionary<string, object> variables, FormulaEvaluator e)
        {
          return this.EvaluateFormula(formula, dataSourceForEvaluate, null, variables, true, e);
        }

        public virtual string EvaluateFormula(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate)
        {
          return this.EvaluateFormula(formula, dataSourceForEvaluate, null, null, true, null);
        }

        public virtual string EvaluateFormula(string formula, bool includeDS)
        {
          return this.EvaluateFormula(formula, null, null, null, includeDS, null);
        }

        public virtual string EvaluateFormula(string formula)
        {
          return this.EvaluateFormula(formula, null, null, null, true, null);
        }
        
      
        public virtual void ResetControl()
        {
          
              this.ID_GasolineraFilter.ClearSelection();
            
              this.ID_Tipo_ServicioFilter.ClearSelection();
            
            this.RecordUniqueId = null;
            this.PageIndex = 0;
            
        }
        

        public virtual void RegisterPostback()
        {
        
                  this.Page.RegisterPostBackTrigger(MiscUtils.FindControlRecursively(this,"GasolineraXTipoGasolineraSaveButton"));
                            
        }
    
        
        protected virtual void BindPaginationControls()
        {
            // Setup the pagination controls.
            // Bind the buttons for GasolineraXTipoGasolineraRecordControl pagination.
        
            this.GasolineraXTipoGasolineraPagination.FirstPage.Enabled = !(this.PageIndex == 0);
            this.GasolineraXTipoGasolineraPagination.LastPage.Enabled = !(this.PageIndex == this.TotalPages - 1);
            if (this.TotalPages == 0) {
                this.GasolineraXTipoGasolineraPagination.LastPage.Enabled = false;
            }
          
            this.GasolineraXTipoGasolineraPagination.NextPage.Enabled = !(this.PageIndex == this.TotalPages - 1);
            if (this.TotalPages == 0) {
                this.GasolineraXTipoGasolineraPagination.NextPage.Enabled = false;
            }
          
            this.GasolineraXTipoGasolineraPagination.PreviousPage.Enabled = !(this.PageIndex == 0);

            // Bind the pagination labels.
        
            if (this.TotalPages > 0) {
                this.GasolineraXTipoGasolineraPagination.CurrentPage.Text = (this.PageIndex + 1).ToString();
            } else {
                this.GasolineraXTipoGasolineraPagination.CurrentPage.Text = "0";
            }
            this.GasolineraXTipoGasolineraPagination.TotalPages.Text = this.TotalPages.ToString();
        }
        

        public virtual void SaveData()
        {
            // Saves the associated record in the database.
            // SaveData calls Validate and Get methods - so it may be more appropriate to
            // customize those methods.

            // 1. Load the existing record from the database. Since we save the entire record, this ensures 
            // that fields that are not displayed are also properly initialized.
            this.LoadData();
        
            System.Web.UI.WebControls.Panel Panel = (System.Web.UI.WebControls.Panel)MiscUtils.FindControlRecursively(this, "GasolineraXTipoGasolineraRecordControlPanel");
            if ( (Panel != null && !Panel.Visible) || this.DataSource == null){
                return;
            }
          
          
            // 2. Perform any custom validation.
            this.Validate();

            
            // 3. Set the values in the record with data from UI controls.
            // This calls the Get() method for each of the user interface controls.
            this.GetUIData();
   
            // 4. Save in the database.
            // We should not save the record if the data did not change. This
            // will save a database hit and avoid triggering any database triggers.
            
            if (this.DataSource.IsAnyValueChanged) {
                // Save record to database but do not commit yet.
                // Auto generated ids are available after saving for use by child (dependent) records.
                this.DataSource.Save();
                
            }
            
      
            // update session or cookie by formula
             		  
      
            // Setting the DataChanged to True results in the page being refreshed with
            // the most recent data from the database.  This happens in PreRender event
            // based on the current sort, search and filter criteria.
            this.DataChanged = true;
            this.ResetData = true;
            
            // For Master-Detail relationships, save data on the Detail table(s)
              
        }

        public virtual void GetUIData()
        {
            // The GetUIData method retrieves the updated values from the user interface 
            // controls into a database record in preparation for saving or updating.
            // To do this, it calls the Get methods for each of the field displayed on 
            // the webpage.  It is better to make changes in the Get methods, rather 
            // than making changes here.
      
            // Call the Get methods for each of the user interface controls.
        
            GetID_Gasolinera();
            GetID_Tipo_Servicio();
        }
        
        
        public virtual void GetID_Gasolinera()
        {
         // Retrieve the value entered by the user on the ID_Gasolinera ASP:DropDownList, and
            // save it into the ID_Gasolinera field in DataSource GasolineraXTipoGasolinera record.
            
            // Custom validation should be performed in Validate, not here.
            
            this.DataSource.Parse(MiscUtils.GetValueSelectedPageRequest(this.ID_Gasolinera), GasolineraXTipoGasolineraTable.ID_Gasolinera);			
                			 
        }
                
        public virtual void GetID_Tipo_Servicio()
        {
         // Retrieve the value entered by the user on the ID_Tipo_Servicio ASP:DropDownList, and
            // save it into the ID_Tipo_Servicio field in DataSource GasolineraXTipoGasolinera record.
            
            // Custom validation should be performed in Validate, not here.
            
            this.DataSource.Parse(MiscUtils.GetValueSelectedPageRequest(this.ID_Tipo_Servicio), GasolineraXTipoGasolineraTable.ID_Tipo_Servicio);			
                			 
        }
                
        public virtual CompoundFilter CreateCompoundJoinFilter()
        {
            CompoundFilter jFilter = new CompoundFilter();
        
            return jFilter;
        }            
        
        
        public virtual OrderBy CreateOrderBy()
        {
            return this.CurrentSortOrder;
        }
        

      // To customize, override this method in GasolineraXTipoGasolineraRecordControl.
      
        public virtual WhereClause CreateWhereClause()
         
        {
        
            WhereClause wc;
            GasolineraXTipoGasolineraTable.Instance.InnerFilter = null;
            wc = new WhereClause();
            
            // Compose the WHERE clause consiting of:
            // 1. Static clause defined at design time.
            // 2. User selected search criteria.
            // 3. User selected filter criteria.

              
            if (MiscUtils.IsValueSelected(this.ID_GasolineraFilter)) {
                        
                int selectedItemCount = 0;
                foreach (ListItem item in this.ID_GasolineraFilter.Items){
                    if (item.Selected) {
                        selectedItemCount += 1;
                        
                          
                    }
                }
              
                WhereClause filter = new WhereClause();
                foreach (ListItem item in this.ID_GasolineraFilter.Items){
                    if ((item.Selected) && ((item.Value == "--ANY--") || (item.Value == "--PLEASE_SELECT--")) && (selectedItemCount > 1)){
                        item.Selected = false;
                    }
                    if (item.Selected){
                        filter.iOR(GasolineraXTipoGasolineraTable.ID_Gasolinera, BaseFilter.ComparisonOperator.EqualsTo, item.Value, false, false);
                    }
                }
                wc.iAND(filter);
              
            }
                      
            if (MiscUtils.IsValueSelected(this.ID_Tipo_ServicioFilter)) {
                        
                int selectedItemCount = 0;
                foreach (ListItem item in this.ID_Tipo_ServicioFilter.Items){
                    if (item.Selected) {
                        selectedItemCount += 1;
                        
                          
                    }
                }
              
                WhereClause filter = new WhereClause();
                foreach (ListItem item in this.ID_Tipo_ServicioFilter.Items){
                    if ((item.Selected) && ((item.Value == "--ANY--") || (item.Value == "--PLEASE_SELECT--")) && (selectedItemCount > 1)){
                        item.Selected = false;
                    }
                    if (item.Selected){
                        filter.iOR(GasolineraXTipoGasolineraTable.ID_Tipo_Servicio, BaseFilter.ComparisonOperator.EqualsTo, item.Value, false, false);
                    }
                }
                wc.iAND(filter);
              
            }
                      
            bool bAnyFiltersChanged = false;
                
            if (MiscUtils.IsValueSelected(this.ID_GasolineraFilter) || this.InSession(this.ID_GasolineraFilter)){
                bAnyFiltersChanged = true;
                }
            
            if (MiscUtils.IsValueSelected(this.ID_Tipo_ServicioFilter) || this.InSession(this.ID_Tipo_ServicioFilter)){
                bAnyFiltersChanged = true;
                }
            
            if (bAnyFiltersChanged) {
               return wc;
            }
                
            else {
                
                wc.RunQuery = false;
                
            }
                
            // Retrieve the record id from the URL parameter.
              
            string recId = this.Page.Request.QueryString["GasolineraXTipoGasolinera"];
                
            if (recId != null && recId.Length != 0) {
                HttpContext.Current.Session["QueryString in SearchEditGasolineraXTipoGasolinera"] = recId;
              
                if (KeyValue.IsXmlKey(recId)) {
                    // Keys are typically passed as XML structures to handle composite keys.
                    // If XML, then add a Where clause based on the Primary Key in the XML.
                    KeyValue pkValue = KeyValue.XmlToKey(recId);
            
                wc.iAND(GasolineraXTipoGasolineraTable.ID_Gasolinera, BaseFilter.ComparisonOperator.EqualsTo, pkValue.GetColumnValueString(GasolineraXTipoGasolineraTable.ID_Gasolinera));
        
                wc.iAND(GasolineraXTipoGasolineraTable.ID_Tipo_Servicio, BaseFilter.ComparisonOperator.EqualsTo, pkValue.GetColumnValueString(GasolineraXTipoGasolineraTable.ID_Tipo_Servicio));
             
                }
                else {
                    // The URL parameter contains the actual value, not an XML structure.
            
                wc.iAND(GasolineraXTipoGasolineraTable.ID_Gasolinera, BaseFilter.ComparisonOperator.EqualsTo, recId);
        
                wc.iAND(GasolineraXTipoGasolineraTable.ID_Tipo_Servicio, BaseFilter.ComparisonOperator.EqualsTo, recId);
             
                }
              
                return wc;
            }
                
            return wc;
          
        }
        
        
        public virtual WhereClause CreateWhereClause(String searchText, String fromSearchControl, String AutoTypeAheadSearch, String AutoTypeAheadWordSeparators)
        {
            // This CreateWhereClause is used for loading list of suggestions for Auto Type-Ahead feature.
            GasolineraXTipoGasolineraTable.Instance.InnerFilter = null;
            WhereClause wc= new WhereClause();
        
            // Compose the WHERE clause consiting of:
            // 1. Static clause defined at design time.
            // 2. User selected search criteria.
            // 3. User selected filter criteria.
            String appRelativeVirtualPath = (String)HttpContext.Current.Session["AppRelativeVirtualPath"];
            
            // Adds clauses if values are selected in Filter controls which are configured in the page.
            
      String ID_GasolineraFilterSelectedValue = (String)HttpContext.Current.Session[HttpContext.Current.Session.SessionID + appRelativeVirtualPath + "ID_GasolineraFilter_Ajax"];
            if (MiscUtils.IsValueSelected(ID_GasolineraFilterSelectedValue)) {
              
        if (ID_GasolineraFilterSelectedValue != null){
                        string[] ID_GasolineraFilteritemListFromSession = ID_GasolineraFilterSelectedValue.Split(',');
                        int index = 0;
                  
                        WhereClause filter = new WhereClause();
                        foreach (string item in ID_GasolineraFilteritemListFromSession)
                        {
                            if (index == 0 && item.ToString().Equals(""))
                            {
                            }
                            else
                            {
                                filter.iOR(GasolineraXTipoGasolineraTable.ID_Gasolinera, BaseFilter.ComparisonOperator.EqualsTo, item, false, false);
                                index += 1;
                            }
                        }
                        wc.iAND(filter);
                  
        }
                
      }
                      
      String ID_Tipo_ServicioFilterSelectedValue = (String)HttpContext.Current.Session[HttpContext.Current.Session.SessionID + appRelativeVirtualPath + "ID_Tipo_ServicioFilter_Ajax"];
            if (MiscUtils.IsValueSelected(ID_Tipo_ServicioFilterSelectedValue)) {
              
        if (ID_Tipo_ServicioFilterSelectedValue != null){
                        string[] ID_Tipo_ServicioFilteritemListFromSession = ID_Tipo_ServicioFilterSelectedValue.Split(',');
                        int index = 0;
                  
                        WhereClause filter = new WhereClause();
                        foreach (string item in ID_Tipo_ServicioFilteritemListFromSession)
                        {
                            if (index == 0 && item.ToString().Equals(""))
                            {
                            }
                            else
                            {
                                filter.iOR(GasolineraXTipoGasolineraTable.ID_Tipo_Servicio, BaseFilter.ComparisonOperator.EqualsTo, item, false, false);
                                index += 1;
                            }
                        }
                        wc.iAND(filter);
                  
        }
                
      }
                      
            // Retrieve the record id from the session.
            string recId = HttpContext.Current.Session["QueryString in SearchEditGasolineraXTipoGasolinera"] as string;
            if (recId != null && recId.Trim() != ""){
                if (KeyValue.IsXmlKey(recId)){
                    KeyValue pkValue = KeyValue.XmlToKey(recId);
                
                wc.iAND(GasolineraXTipoGasolineraTable.ID_Gasolinera, BaseFilter.ComparisonOperator.EqualsTo, pkValue.GetColumnValueString(GasolineraXTipoGasolineraTable.ID_Gasolinera));
        
                wc.iAND(GasolineraXTipoGasolineraTable.ID_Tipo_Servicio, BaseFilter.ComparisonOperator.EqualsTo, pkValue.GetColumnValueString(GasolineraXTipoGasolineraTable.ID_Tipo_Servicio));
             
                }
                else
                {
                
                wc.iAND(GasolineraXTipoGasolineraTable.ID_Gasolinera, BaseFilter.ComparisonOperator.EqualsTo, recId);
        
                wc.iAND(GasolineraXTipoGasolineraTable.ID_Tipo_Servicio, BaseFilter.ComparisonOperator.EqualsTo, recId);
             
                }
            }
                          
            return wc;
        }
          
        
        public virtual bool FormatSuggestions(String prefixText, String resultItem,
                                              int columnLength, String AutoTypeAheadDisplayFoundText,
                                              String autoTypeAheadSearch, String AutoTypeAheadWordSeparators,
                                              ArrayList resultList)
        {
            // Formats the result Item and adds it to the list of suggestions.
            int index  = resultItem.ToUpper(System.Threading.Thread.CurrentThread.CurrentCulture).IndexOf(prefixText.ToUpper(System.Threading.Thread.CurrentThread.CurrentCulture));
            String itemToAdd = null;
            bool isFound = false;
            bool isAdded = false;
            if (StringUtils.InvariantLCase(autoTypeAheadSearch).Equals("wordsstartingwithsearchstring") && !(index == 0)) {
                // Expression to find word which contains AutoTypeAheadWordSeparators followed by prefixText
                System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex( AutoTypeAheadWordSeparators + prefixText, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                if (regex1.IsMatch(resultItem)) {
                    index = regex1.Match(resultItem).Index;
                    isFound = true;
                }
                //If the prefixText is found immediatly after white space then starting of the word is found so don not search any further
                if (resultItem[index].ToString() != " ") {
                    // Expression to find beginning of the word which contains AutoTypeAheadWordSeparators followed by prefixText
                    System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("\\S*" + AutoTypeAheadWordSeparators + prefixText, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    if (regex.IsMatch(resultItem)) {
                        index = regex.Match(resultItem).Index;
                        isFound = true;
                    }
                }
            }
            // If autoTypeAheadSearch value is wordsstartingwithsearchstring then, extract the substring only if the prefixText is found at the 
            // beginning of the resultItem (index = 0) or a word in resultItem is found starts with prefixText. 
            if (index == 0 || isFound || StringUtils.InvariantLCase(autoTypeAheadSearch).Equals("anywhereinstring")) {
                if (StringUtils.InvariantLCase(AutoTypeAheadDisplayFoundText).Equals("atbeginningofmatchedstring")) {
                    // Expression to find beginning of the word which contains prefixText
                    System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex("\\S*" + prefixText, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    //  Find the beginning of the word which contains prefexText
                    if (StringUtils.InvariantLCase(autoTypeAheadSearch).Equals("anywhereinstring") && regex1.IsMatch(resultItem)) {
                        index = regex1.Match(resultItem).Index;
                        isFound = true;
                    }
                    // Display string from the index till end of the string if, sub string from index till end of string is less than columnLength value.
                    if ((resultItem.Length - index) <= columnLength) {
                        if (index == 0) {
                            itemToAdd = resultItem;
                        } else {
                            itemToAdd = "..." + resultItem.Substring(index, resultItem.Length - index);
                        }
                    }
                    else {
                        if (index == 0) {
                            itemToAdd = resultItem.Substring(index, (columnLength - 3)) + "...";
                        }
                        else {
                            // Truncate the string to show only columnLength - 6 characters as begining and trailing "..." has to be appended.
                            itemToAdd = "..." + resultItem.Substring(index, (columnLength - 6)) + "...";
                        }
                    }
                }
                else if (StringUtils.InvariantLCase(AutoTypeAheadDisplayFoundText).Equals("inmiddleofmatchedstring")) {
                    int subStringBeginIndex = (int)(columnLength / 2);
                    if (resultItem.Length <= columnLength) {
                        itemToAdd = resultItem;
                    }
                    else {
                        // Sanity check at end of the string
                        if ((index + prefixText.Length) == columnLength) {
                            itemToAdd = "..." + resultItem.Substring((index - columnLength), index);
                        }
                        else if ((resultItem.Length - index) < subStringBeginIndex) {
                            //  Display string from the end till columnLength value if, index is closer to the end of the string.
                            itemToAdd = "..." + resultItem.Substring(resultItem.Length - columnLength, resultItem.Length);
                        }
                        else if (index <= subStringBeginIndex) {
                            // Sanity chet at beginning of the string
                            itemToAdd = resultItem.Substring(0, columnLength) + "...";
                        } 
                        else {
                            // Display string containing text before the prefixText occures and text after the prefixText
                            itemToAdd = "..." + resultItem.Substring(index - subStringBeginIndex, columnLength) + "...";
                        }
                    }
                }
                else if (StringUtils.InvariantLCase(AutoTypeAheadDisplayFoundText).Equals("atendofmatchedstring")) {
                     // Expression to find ending of the word which contains prefexText
                    System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex("\\s", System.Text.RegularExpressions.RegexOptions.IgnoreCase); 
                    // Find the ending of the word which contains prefexText
                    if (regex1.IsMatch(resultItem, index + 1)) {
                        index = regex1.Match(resultItem, index + 1).Index;
                    }
                    else{
                        // If the word which contains prefexText is the last word in string, regex1.IsMatch returns false.
                        index = resultItem.Length;
                    }
                    
                    if (index > resultItem.Length) {
                        index = resultItem.Length;
                    }
                    // If text from beginning of the string till index is less than columnLength value then, display string from the beginning till index.
                    if (index <= columnLength) {
                        if (index == resultItem.Length) {   //Make decision to append "..."
                            itemToAdd = resultItem.Substring(0, index);
                        }
                        else {
                            itemToAdd = resultItem.Substring(0, index) + "...";
                        }
                    } 
                    else if (index == resultItem.Length) {
                        itemToAdd = "..." + resultItem.Substring(index - (columnLength - 3), columnLength - 3);
                    } 
                    else {
                        // Truncate the string to show only columnLength - 6 characters as begining and trailing "..." has to be appended.
                        itemToAdd = "..." + resultItem.Substring(index - (columnLength - 6), (columnLength - 6)) + "...";
                    }
                }
                
                // Remove newline character from itemToAdd
                int prefixTextIndex = itemToAdd.IndexOf(prefixText, StringComparison.CurrentCultureIgnoreCase);
                // If itemToAdd contains any newline after the search text then show text only till newline
                System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex("(\r\n|\n)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                int newLineIndexAfterPrefix = -1;
                if (regex2.IsMatch(itemToAdd, prefixTextIndex)){
                    newLineIndexAfterPrefix = regex2.Match(itemToAdd, prefixTextIndex).Index;
                }
                if ((newLineIndexAfterPrefix > -1)) {
                    if (itemToAdd.EndsWith("...")) {
                        itemToAdd = itemToAdd.Substring(0, newLineIndexAfterPrefix) + "...";
                    }
                    else {
                        itemToAdd = itemToAdd.Substring(0, newLineIndexAfterPrefix);
                    }
                }
                // If itemToAdd contains any newline before search text then show text which comes after newline
                System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex("(\r\n|\n)", System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.RightToLeft );
                int newLineIndexBeforePrefix = -1;
                if (regex3.IsMatch(itemToAdd, prefixTextIndex)){
                    newLineIndexBeforePrefix = regex3.Match(itemToAdd, prefixTextIndex).Index;
                }
                if ((newLineIndexBeforePrefix > -1)) {
                    if (itemToAdd.StartsWith("...")) {
                        itemToAdd = "..." + itemToAdd.Substring(newLineIndexBeforePrefix +regex3.Match(itemToAdd, prefixTextIndex).Length);
                    }
                    else {
                        itemToAdd = itemToAdd.Substring(newLineIndexBeforePrefix +regex3.Match(itemToAdd, prefixTextIndex).Length);
                    }
                }

                if (itemToAdd!= null && !resultList.Contains(itemToAdd)) {
                    resultList.Add(itemToAdd);
                    isAdded = true;
                }
            }
            return isAdded;
        }
        
        public virtual void SetID_GasolineraFilter()
        {
            
            ArrayList ID_GasolineraFilterselectedFilterItemList = new ArrayList();
            string ID_GasolineraFilteritemsString = null;
            if (this.InSession(this.ID_GasolineraFilter))
                ID_GasolineraFilteritemsString = this.GetFromSession(this.ID_GasolineraFilter);

            if (ID_GasolineraFilteritemsString != null){
                string[] ID_GasolineraFilteritemListFromSession = ID_GasolineraFilteritemsString.Split(',');
                foreach (string item in ID_GasolineraFilteritemListFromSession){
                    ID_GasolineraFilterselectedFilterItemList.Add(item);
                }
            }					
            this.PopulateID_GasolineraFilter(MiscUtils.GetSelectedValueList(this.ID_GasolineraFilter, ID_GasolineraFilterselectedFilterItemList), 500);
                    
        }
            
        public virtual void SetID_Tipo_ServicioFilter()
        {
            
            ArrayList ID_Tipo_ServicioFilterselectedFilterItemList = new ArrayList();
            string ID_Tipo_ServicioFilteritemsString = null;
            if (this.InSession(this.ID_Tipo_ServicioFilter))
                ID_Tipo_ServicioFilteritemsString = this.GetFromSession(this.ID_Tipo_ServicioFilter);

            if (ID_Tipo_ServicioFilteritemsString != null){
                string[] ID_Tipo_ServicioFilteritemListFromSession = ID_Tipo_ServicioFilteritemsString.Split(',');
                foreach (string item in ID_Tipo_ServicioFilteritemListFromSession){
                    ID_Tipo_ServicioFilterselectedFilterItemList.Add(item);
                }
            }					
            this.PopulateID_Tipo_ServicioFilter(MiscUtils.GetSelectedValueList(this.ID_Tipo_ServicioFilter, ID_Tipo_ServicioFilterselectedFilterItemList), 500);
                    
        }
            
        // Get the filters' data for ID_GasolineraFilter.
                
        protected virtual void PopulateID_GasolineraFilter(ArrayList selectedValue, int maxItems)
                    
        {
            this.ID_GasolineraFilter.Items.Clear();
                        
            		  			
            // Set up the WHERE and the ORDER BY clause by calling the CreateWhereClause_ID_GasolineraFilter function.
            // It is better to customize the where clause there.
          						
            //Setup the WHERE clause.
            WhereClause wc =this.CreateWhereClause_ID_GasolineraFilter();		
            
            // Setup the static list items        
            
            // Add the Please Select item.
            this.ID_GasolineraFilter.Items.Insert(0, new ListItem(this.Page.GetResourceValue("Txt:PleaseSelect", "EnGasAdoAPP"), "--PLEASE_SELECT--"));
                            
            OrderBy orderBy = new OrderBy(false, false);
                          orderBy.Add(GasolineraTable.Descripcion, OrderByItem.OrderDir.Asc);


            System.Collections.Generic.IDictionary<string, object> variables = new System.Collections.Generic.Dictionary<string, object> ();

            

            string noValueFormat = Page.GetResourceValue("Txt:Other", "EnGasAdoAPP");

            GasolineraRecord[] itemValues  = null;
            if (wc.RunQuery)
            {
                int counter = 0;
                int pageNum = 0;
                FormulaEvaluator evaluator = new FormulaEvaluator();
                
                
                do
                {
                    
                    itemValues = GasolineraTable.GetRecords(wc, orderBy, pageNum, maxItems);
                                    
                    foreach (GasolineraRecord itemValue in itemValues) 
                    {
                        // Create the item and add to the list.
                        string cvalue = null;
                        string fvalue = null;
                        if (itemValue.ID_GasolineraSpecified) 
                        {
                            cvalue = itemValue.ID_Gasolinera.ToString();
                            if (counter < maxItems && this.ID_GasolineraFilter.Items.FindByValue(cvalue) == null)
                            {
                                    
                                Boolean _isExpandableNonCompositeForeignKey = GasolineraXTipoGasolineraTable.Instance.TableDefinition.IsExpandableNonCompositeForeignKey(GasolineraXTipoGasolineraTable.ID_Gasolinera);
                                if(_isExpandableNonCompositeForeignKey && GasolineraXTipoGasolineraTable.ID_Gasolinera.IsApplyDisplayAs)
                                     fvalue = GasolineraXTipoGasolineraTable.GetDFKA(itemValue, GasolineraXTipoGasolineraTable.ID_Gasolinera);
                                if ((!_isExpandableNonCompositeForeignKey) || (String.IsNullOrEmpty(fvalue)))
                                     fvalue = itemValue.Format(GasolineraTable.Descripcion);
                                   					
                                if (fvalue == null || fvalue.Trim() == "") fvalue = cvalue;
                                ListItem newItem = new ListItem(fvalue, cvalue);
                                this.ID_GasolineraFilter.Items.Add(newItem);
                                counter += 1;
                            }
                        }
                    }
                    pageNum++;
                }
                while (itemValues.Length == maxItems && counter < maxItems);
            }
        
          
      
            // Set the selected value.
            MiscUtils.SetSelectedValue(this.ID_GasolineraFilter, selectedValue);

            


            if ((this.ID_GasolineraFilter.SelectedValue == null) || (selectedValue == null) || (selectedValue.Count == 0)){
                
        this.ID_GasolineraFilter.SelectedValue = "--PLEASE_SELECT--";
        }
      
        }
            
        // Get the filters' data for ID_Tipo_ServicioFilter.
                
        protected virtual void PopulateID_Tipo_ServicioFilter(ArrayList selectedValue, int maxItems)
                    
        {
            this.ID_Tipo_ServicioFilter.Items.Clear();
                        
            		  			
            // Set up the WHERE and the ORDER BY clause by calling the CreateWhereClause_ID_Tipo_ServicioFilter function.
            // It is better to customize the where clause there.
          						
            //Setup the WHERE clause.
            WhereClause wc =this.CreateWhereClause_ID_Tipo_ServicioFilter();		
            
            // Setup the static list items        
            
            // Add the Please Select item.
            this.ID_Tipo_ServicioFilter.Items.Insert(0, new ListItem(this.Page.GetResourceValue("Txt:PleaseSelect", "EnGasAdoAPP"), "--PLEASE_SELECT--"));
                            
            OrderBy orderBy = new OrderBy(false, false);
                          orderBy.Add(Tipo_ServicioTable.Descripcion, OrderByItem.OrderDir.Asc);


            System.Collections.Generic.IDictionary<string, object> variables = new System.Collections.Generic.Dictionary<string, object> ();

            

            string noValueFormat = Page.GetResourceValue("Txt:Other", "EnGasAdoAPP");

            Tipo_ServicioRecord[] itemValues  = null;
            if (wc.RunQuery)
            {
                int counter = 0;
                int pageNum = 0;
                FormulaEvaluator evaluator = new FormulaEvaluator();
                
                
                do
                {
                    
                    itemValues = Tipo_ServicioTable.GetRecords(wc, orderBy, pageNum, maxItems);
                                    
                    foreach (Tipo_ServicioRecord itemValue in itemValues) 
                    {
                        // Create the item and add to the list.
                        string cvalue = null;
                        string fvalue = null;
                        if (itemValue.ID_Tipo_ServicioSpecified) 
                        {
                            cvalue = itemValue.ID_Tipo_Servicio.ToString();
                            if (counter < maxItems && this.ID_Tipo_ServicioFilter.Items.FindByValue(cvalue) == null)
                            {
                                    
                                Boolean _isExpandableNonCompositeForeignKey = GasolineraXTipoGasolineraTable.Instance.TableDefinition.IsExpandableNonCompositeForeignKey(GasolineraXTipoGasolineraTable.ID_Tipo_Servicio);
                                if(_isExpandableNonCompositeForeignKey && GasolineraXTipoGasolineraTable.ID_Tipo_Servicio.IsApplyDisplayAs)
                                     fvalue = GasolineraXTipoGasolineraTable.GetDFKA(itemValue, GasolineraXTipoGasolineraTable.ID_Tipo_Servicio);
                                if ((!_isExpandableNonCompositeForeignKey) || (String.IsNullOrEmpty(fvalue)))
                                     fvalue = itemValue.Format(Tipo_ServicioTable.Descripcion);
                                   					
                                if (fvalue == null || fvalue.Trim() == "") fvalue = cvalue;
                                ListItem newItem = new ListItem(fvalue, cvalue);
                                this.ID_Tipo_ServicioFilter.Items.Add(newItem);
                                counter += 1;
                            }
                        }
                    }
                    pageNum++;
                }
                while (itemValues.Length == maxItems && counter < maxItems);
            }
        
          
      
            // Set the selected value.
            MiscUtils.SetSelectedValue(this.ID_Tipo_ServicioFilter, selectedValue);

            


            if ((this.ID_Tipo_ServicioFilter.SelectedValue == null) || (selectedValue == null) || (selectedValue.Count == 0)){
                
        this.ID_Tipo_ServicioFilter.SelectedValue = "--PLEASE_SELECT--";
        }
      
        }
            
        public virtual WhereClause CreateWhereClause_ID_GasolineraFilter()
        {
        
            // Create a where clause for the filter ID_GasolineraFilter.
            // This function is called by the Populate method to load the items 
            // in the ID_GasolineraFilterListBox
        
            WhereClause wc = new WhereClause();
            return wc;
            
        }
      
        public virtual WhereClause CreateWhereClause_ID_Tipo_ServicioFilter()
        {
        
            // Create a where clause for the filter ID_Tipo_ServicioFilter.
            // This function is called by the Populate method to load the items 
            // in the ID_Tipo_ServicioFilterListBox
        
            WhereClause wc = new WhereClause();
            return wc;
            
        }
      
    
        public virtual void Validate()
        {
            // Add custom validation for any control within this panel.
            // Example.  If you have a State ASP:Textbox control
            // if (this.State.Text != "CA")
            //    throw new Exception("State must be CA (California).");
            // The Validate method is common across all controls within
            // this panel so you can validate multiple fields, but report
            // one error message.
            
            
            
        }

        public virtual void Delete()
        {
        
            if (this.IsNewRecord) {
                return;
            }

            KeyValue pkValue = KeyValue.XmlToKey(this.RecordUniqueId);
          GasolineraXTipoGasolineraTable.DeleteRecord(pkValue);
          
        }

        protected virtual void Control_PreRender(object sender, System.EventArgs e)
        {
            // PreRender event is raised just before page is being displayed.
            try {
                DbUtils.StartTransaction();
                this.RegisterPostback();
                if (!this.Page.ErrorOnPage && (this.Page.IsPageRefresh || this.DataChanged || this.ResetData)) {
                  
                
                    // Re-load the data and update the web page if necessary.
                    // This is typically done during a postback (filter, search button, sort, pagination button).
                    // In each of the other click handlers, simply set DataChanged to True to reload the data.
                    this.LoadData();
                    this.DataBind();
                }
                				
            } catch (Exception ex) {
                BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
            } finally {
                DbUtils.EndTransaction();
            }
        }
        
            
        protected override void SaveControlsToSession()
        {
            base.SaveControlsToSession();
        
            // Save filter controls to values to session.
        
            ArrayList ID_GasolineraFilterselectedFilterItemList = MiscUtils.GetSelectedValueList(this.ID_GasolineraFilter, null);
            string ID_GasolineraFilterSessionString = "";
            if (ID_GasolineraFilterselectedFilterItemList != null){
                foreach (string item in ID_GasolineraFilterselectedFilterItemList){
                    ID_GasolineraFilterSessionString = String.Concat(ID_GasolineraFilterSessionString ,"," , item);
                }
            }
            this.SaveToSession(this.ID_GasolineraFilter, ID_GasolineraFilterSessionString);
                  
            ArrayList ID_Tipo_ServicioFilterselectedFilterItemList = MiscUtils.GetSelectedValueList(this.ID_Tipo_ServicioFilter, null);
            string ID_Tipo_ServicioFilterSessionString = "";
            if (ID_Tipo_ServicioFilterselectedFilterItemList != null){
                foreach (string item in ID_Tipo_ServicioFilterselectedFilterItemList){
                    ID_Tipo_ServicioFilterSessionString = String.Concat(ID_Tipo_ServicioFilterSessionString ,"," , item);
                }
            }
            this.SaveToSession(this.ID_Tipo_ServicioFilter, ID_Tipo_ServicioFilterSessionString);
                  
            
            // Save table control properties to the session.
            
            if (this.CurrentSortOrder != null)
                this.SaveToSession(this, "Order_By", this.CurrentSortOrder.ToXmlString());
            
            
            this.SaveToSession(this, "Page_Index", this.PageIndex.ToString());
        
    
            // Save pagination state to session.
          
        }
        
        
        protected void SaveControlsToSession_Ajax()
        {
            // Save filter controls to values to session.
          
            ArrayList ID_GasolineraFilterselectedFilterItemList = MiscUtils.GetSelectedValueList(this.ID_GasolineraFilter, null);
            string ID_GasolineraFilterSessionString = "";
            if (ID_GasolineraFilterselectedFilterItemList != null){
                foreach (string item in ID_GasolineraFilterselectedFilterItemList){
                    ID_GasolineraFilterSessionString = String.Concat(ID_GasolineraFilterSessionString ,"," , item);
                }
            }
            this.SaveToSession("ID_GasolineraFilter_Ajax", ID_GasolineraFilterSessionString);
          
            ArrayList ID_Tipo_ServicioFilterselectedFilterItemList = MiscUtils.GetSelectedValueList(this.ID_Tipo_ServicioFilter, null);
            string ID_Tipo_ServicioFilterSessionString = "";
            if (ID_Tipo_ServicioFilterselectedFilterItemList != null){
                foreach (string item in ID_Tipo_ServicioFilterselectedFilterItemList){
                    ID_Tipo_ServicioFilterSessionString = String.Concat(ID_Tipo_ServicioFilterSessionString ,"," , item);
                }
            }
            this.SaveToSession("ID_Tipo_ServicioFilter_Ajax", ID_Tipo_ServicioFilterSessionString);
          
            HttpContext.Current.Session["AppRelativeVirtualPath"] = this.Page.AppRelativeVirtualPath;
         
        }
        
    
        protected override void ClearControlsFromSession()
        {
            base.ClearControlsFromSession();

        
            // Clear filter controls values from the session.
        
            this.RemoveFromSession(this.ID_GasolineraFilter);
            this.RemoveFromSession(this.ID_Tipo_ServicioFilter);
          
            // Clear table properties from the session.
            
            this.RemoveFromSession(this, "Page_Index");
            

            // Clear pagination state from session.
        
        }
        
        protected override void LoadViewState(object savedState)
        {
            base.LoadViewState(savedState);
            string isNewRecord = (string)ViewState["IsNewRecord"];
            if (isNewRecord != null && isNewRecord.Length > 0) {
                this.IsNewRecord = Boolean.Parse(isNewRecord);
            }
        
            string pageIndex = (string)ViewState["Page_Index"];
            if (pageIndex != null) {
                this.PageIndex = Int32.Parse(pageIndex);
            }
            
            string orderByStr = (string)ViewState["GasolineraXTipoGasolineraRecordControl_OrderBy"];
          
            if (orderByStr != null && orderByStr.Length > 0) {
                this.CurrentSortOrder = BaseClasses.Data.OrderBy.FromXmlString(orderByStr);
            }
            else {
                this.CurrentSortOrder = new OrderBy(true, false);
            }
          
    
            // Load view state for pagination control.
                 
        }

        protected override object SaveViewState()
        {
            ViewState["IsNewRecord"] = this.IsNewRecord.ToString();
            ViewState["CheckSum"] = this.CheckSum;
        
            ViewState["Page_Index"] = this.PageIndex.ToString();
            
          
            if (this.CurrentSortOrder != null) {
                this.ViewState["GasolineraXTipoGasolineraRecordControl_OrderBy"] = this.CurrentSortOrder.ToXmlString();
            }
          

            // Load view state for pagination control.
               
            return base.SaveViewState();
        }

        
        // Generate the event handling functions for pagination events.
            
        // Event handler for GasolineraXTipoGasolineraPaginationImageButton .
        public virtual void GasolineraXTipoGasolineraPagination_FirstPage_Click(object sender, ImageClickEventArgs args)
        {
        
            try {
                
            this.PageIndex = 0;
            this.DataChanged = true;
      
            } catch (Exception ex) {
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
    
            }
    
        }
        
        // Event handler for GasolineraXTipoGasolineraPaginationImageButton .
        public virtual void GasolineraXTipoGasolineraPagination_LastPage_Click(object sender, ImageClickEventArgs args)
        {
        
            try {
                
            this.DisplayLastPage = true;
            this.DataChanged = true;
      
            } catch (Exception ex) {
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
    
            }
    
        }
        
        // Event handler for GasolineraXTipoGasolineraPaginationImageButton .
        public virtual void GasolineraXTipoGasolineraPagination_NextPage_Click(object sender, ImageClickEventArgs args)
        {
        
            try {
                
            this.PageIndex += 1;
            this.DataChanged = true;
      
            } catch (Exception ex) {
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
    
            }
    
        }
        
        // event handler for GasolineraXTipoGasolineraPaginationPageSizeButtonLinkButton  
        public virtual void GasolineraXTipoGasolineraPagination_PageSizeButton_Click(object sender, EventArgs args)
        {
        
            try {
                
            this.DataChanged = true;
      
            this.PageIndex = Convert.ToInt32(this.GasolineraXTipoGasolineraPagination.CurrentPage.Text) - 1;
      
            } catch (Exception ex) {
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
    
            }
    
        }
        
        // Event handler for GasolineraXTipoGasolineraPaginationImageButton .
        public virtual void GasolineraXTipoGasolineraPagination_PreviousPage_Click(object sender, ImageClickEventArgs args)
        {
        
            try {
                
            if (this.PageIndex > 0) {
                this.PageIndex -= 1;
                this.DataChanged = true;
            }
      
            } catch (Exception ex) {
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
    
            }
    
        }
        
      
        // Generate the event handling functions for filter and search events.
            
        // event handler for FieldFilter
        protected virtual void ID_GasolineraFilter_SelectedIndexChanged(object sender, EventArgs args)
        {
            // Setting the DataChanged to True results in the page being refreshed with
            // the most recent data from the database.  This happens in PreRender event
            // based on the current sort, search and filter criteria.
            this.DataChanged = true;
            
           				
        }
            
        // event handler for FieldFilter
        protected virtual void ID_Tipo_ServicioFilter_SelectedIndexChanged(object sender, EventArgs args)
        {
            // Setting the DataChanged to True results in the page being refreshed with
            // the most recent data from the database.  This happens in PreRender event
            // based on the current sort, search and filter criteria.
            this.DataChanged = true;
            
           				
        }
            
        public virtual WhereClause CreateWhereClause_ID_GasolineraDropDownList() 
        {
            // By default, we simply return a new WhereClause.
            // Add additional where clauses to restrict the items shown in the dropdown list.
            						
            // This WhereClause is for the Gasolinera table.
            // Examples:
            // wc.iAND(GasolineraTable.Descripcion, BaseFilter.ComparisonOperator.EqualsTo, "XYZ");
            // wc.iAND(GasolineraTable.Active, BaseFilter.ComparisonOperator.EqualsTo, "1");
            
            WhereClause wc = new WhereClause();
            return wc;
            				
        }
        
        public virtual WhereClause CreateWhereClause_ID_Tipo_ServicioDropDownList() 
        {
            // By default, we simply return a new WhereClause.
            // Add additional where clauses to restrict the items shown in the dropdown list.
            						
            // This WhereClause is for the Tipo_Servicio table.
            // Examples:
            // wc.iAND(Tipo_ServicioTable.Descripcion, BaseFilter.ComparisonOperator.EqualsTo, "XYZ");
            // wc.iAND(Tipo_ServicioTable.Active, BaseFilter.ComparisonOperator.EqualsTo, "1");
            
            WhereClause wc = new WhereClause();
            return wc;
            				
        }
        
        // Fill the ID_Gasolinera list.
        protected virtual void PopulateID_GasolineraDropDownList(string selectedValue, int maxItems) 
        {
            this.ID_Gasolinera.Items.Clear();
            

                       
                      
            // 1. Setup the static list items        
            
            // Add the Please Select item.
            this.ID_Gasolinera.Items.Insert(0, new ListItem(this.Page.GetResourceValue("Txt:PleaseSelect", "EnGasAdoAPP"), "--PLEASE_SELECT--"));
                            		  			
            // 2. Set up the WHERE and the ORDER BY clause by calling the CreateWhereClause_ID_GasolineraDropDownList function.
            // It is better to customize the where clause there.
            
                      
            WhereClause wc = CreateWhereClause_ID_GasolineraDropDownList();
                        
                
            // Create the ORDER BY clause to sort based on the displayed value.							
                
            OrderBy orderBy = new OrderBy(false, false);
                          orderBy.Add(GasolineraTable.Descripcion, OrderByItem.OrderDir.Asc);

            System.Collections.Generic.IDictionary<string, object> variables = new System.Collections.Generic.Dictionary<string, object> ();

            // 3. Read a total of maxItems from the database and insert them into the ID_GasolineraDropDownList.
            GasolineraRecord[] itemValues  = null;
            if (wc.RunQuery)
            {
                int counter = 0;
                int pageNum = 0;	
                FormulaEvaluator evaluator = new FormulaEvaluator();
                do
                {
                    itemValues = GasolineraTable.GetRecords(wc, orderBy, pageNum, maxItems);
                    foreach (GasolineraRecord itemValue in itemValues) 
                    {
                        // Create the item and add to the list.
                        string cvalue = null;
                        string fvalue = null;
                        if (itemValue.ID_GasolineraSpecified) 
                        {
                            cvalue = itemValue.ID_Gasolinera.ToString().ToString();
                            if (counter < maxItems && this.ID_Gasolinera.Items.FindByValue(cvalue) == null)
                            {
                                     
                                Boolean _isExpandableNonCompositeForeignKey = GasolineraXTipoGasolineraTable.Instance.TableDefinition.IsExpandableNonCompositeForeignKey(GasolineraXTipoGasolineraTable.ID_Gasolinera);
                                if(_isExpandableNonCompositeForeignKey && GasolineraXTipoGasolineraTable.ID_Gasolinera.IsApplyDisplayAs)
                                    fvalue = GasolineraXTipoGasolineraTable.GetDFKA(itemValue, GasolineraXTipoGasolineraTable.ID_Gasolinera);
                                if ((!_isExpandableNonCompositeForeignKey) || (String.IsNullOrEmpty(fvalue)))
                                    fvalue = itemValue.Format(GasolineraTable.Descripcion);
                                    					
                                if (fvalue == null || fvalue.Trim() == "") 
                                    fvalue = cvalue;
                                ListItem newItem = new ListItem(fvalue, cvalue);
                                this.ID_Gasolinera.Items.Add(newItem);
                                counter += 1;
                            }
                        }
                    }
                    pageNum++;
                }
                while (itemValues.Length == maxItems && counter < maxItems);
            }
                        
                                        
            // 4. Set the selected value (insert if not already present).
              
            if (selectedValue != null &&
                selectedValue.Trim() != "" &&
                !MiscUtils.SetSelectedValue(this.ID_Gasolinera, selectedValue) &&
                !MiscUtils.SetSelectedDisplayText(this.ID_Gasolinera, selectedValue))
            {

                // construct a whereclause to query a record with Gasolinera.ID_Gasolinera = selectedValue
                    
                CompoundFilter filter2 = new CompoundFilter(CompoundFilter.CompoundingOperators.And_Operator, null);
                WhereClause whereClause2 = new WhereClause();
                filter2.AddFilter(new BaseClasses.Data.ColumnValueFilter(GasolineraTable.ID_Gasolinera, selectedValue, BaseClasses.Data.BaseFilter.ComparisonOperator.EqualsTo, false));
                whereClause2.AddFilter(filter2, CompoundFilter.CompoundingOperators.And_Operator);

                // Execute the query
                try
                {
                GasolineraRecord[] rc = GasolineraTable.GetRecords(whereClause2, new OrderBy(false, false), 0, 1);
                System.Collections.Generic.IDictionary<string, object> vars = new System.Collections.Generic.Dictionary<string, object> ();
                    // if find a record, add it to the dropdown and set it as selected item
                    if (rc != null && rc.Length == 1)
                    {
                        
                        string fvalue = GasolineraXTipoGasolineraTable.ID_Gasolinera.Format(selectedValue);																				
                            
                        ListItem item = new ListItem(fvalue, selectedValue);
                        item.Selected = true;
                        this.ID_Gasolinera.Items.Add(item);
                    }
                }
                catch
                {
                }

                    					
            }					
                        
        }
                
        // Fill the ID_Tipo_Servicio list.
        protected virtual void PopulateID_Tipo_ServicioDropDownList(string selectedValue, int maxItems) 
        {
            this.ID_Tipo_Servicio.Items.Clear();
            

                       
                      
            // 1. Setup the static list items        
            
            // Add the Please Select item.
            this.ID_Tipo_Servicio.Items.Insert(0, new ListItem(this.Page.GetResourceValue("Txt:PleaseSelect", "EnGasAdoAPP"), "--PLEASE_SELECT--"));
                            		  			
            // 2. Set up the WHERE and the ORDER BY clause by calling the CreateWhereClause_ID_Tipo_ServicioDropDownList function.
            // It is better to customize the where clause there.
            
                      
            WhereClause wc = CreateWhereClause_ID_Tipo_ServicioDropDownList();
                        
                
            // Create the ORDER BY clause to sort based on the displayed value.							
                
            OrderBy orderBy = new OrderBy(false, false);
                          orderBy.Add(Tipo_ServicioTable.Descripcion, OrderByItem.OrderDir.Asc);

            System.Collections.Generic.IDictionary<string, object> variables = new System.Collections.Generic.Dictionary<string, object> ();

            // 3. Read a total of maxItems from the database and insert them into the ID_Tipo_ServicioDropDownList.
            Tipo_ServicioRecord[] itemValues  = null;
            if (wc.RunQuery)
            {
                int counter = 0;
                int pageNum = 0;	
                FormulaEvaluator evaluator = new FormulaEvaluator();
                do
                {
                    itemValues = Tipo_ServicioTable.GetRecords(wc, orderBy, pageNum, maxItems);
                    foreach (Tipo_ServicioRecord itemValue in itemValues) 
                    {
                        // Create the item and add to the list.
                        string cvalue = null;
                        string fvalue = null;
                        if (itemValue.ID_Tipo_ServicioSpecified) 
                        {
                            cvalue = itemValue.ID_Tipo_Servicio.ToString().ToString();
                            if (counter < maxItems && this.ID_Tipo_Servicio.Items.FindByValue(cvalue) == null)
                            {
                                     
                                Boolean _isExpandableNonCompositeForeignKey = GasolineraXTipoGasolineraTable.Instance.TableDefinition.IsExpandableNonCompositeForeignKey(GasolineraXTipoGasolineraTable.ID_Tipo_Servicio);
                                if(_isExpandableNonCompositeForeignKey && GasolineraXTipoGasolineraTable.ID_Tipo_Servicio.IsApplyDisplayAs)
                                    fvalue = GasolineraXTipoGasolineraTable.GetDFKA(itemValue, GasolineraXTipoGasolineraTable.ID_Tipo_Servicio);
                                if ((!_isExpandableNonCompositeForeignKey) || (String.IsNullOrEmpty(fvalue)))
                                    fvalue = itemValue.Format(Tipo_ServicioTable.Descripcion);
                                    					
                                if (fvalue == null || fvalue.Trim() == "") 
                                    fvalue = cvalue;
                                ListItem newItem = new ListItem(fvalue, cvalue);
                                this.ID_Tipo_Servicio.Items.Add(newItem);
                                counter += 1;
                            }
                        }
                    }
                    pageNum++;
                }
                while (itemValues.Length == maxItems && counter < maxItems);
            }
                        
                                        
            // 4. Set the selected value (insert if not already present).
              
            if (selectedValue != null &&
                selectedValue.Trim() != "" &&
                !MiscUtils.SetSelectedValue(this.ID_Tipo_Servicio, selectedValue) &&
                !MiscUtils.SetSelectedDisplayText(this.ID_Tipo_Servicio, selectedValue))
            {

                // construct a whereclause to query a record with Tipo_Servicio.ID_Tipo_Servicio = selectedValue
                    
                CompoundFilter filter2 = new CompoundFilter(CompoundFilter.CompoundingOperators.And_Operator, null);
                WhereClause whereClause2 = new WhereClause();
                filter2.AddFilter(new BaseClasses.Data.ColumnValueFilter(Tipo_ServicioTable.ID_Tipo_Servicio, selectedValue, BaseClasses.Data.BaseFilter.ComparisonOperator.EqualsTo, false));
                whereClause2.AddFilter(filter2, CompoundFilter.CompoundingOperators.And_Operator);

                // Execute the query
                try
                {
                Tipo_ServicioRecord[] rc = Tipo_ServicioTable.GetRecords(whereClause2, new OrderBy(false, false), 0, 1);
                System.Collections.Generic.IDictionary<string, object> vars = new System.Collections.Generic.Dictionary<string, object> ();
                    // if find a record, add it to the dropdown and set it as selected item
                    if (rc != null && rc.Length == 1)
                    {
                        
                        string fvalue = GasolineraXTipoGasolineraTable.ID_Tipo_Servicio.Format(selectedValue);																				
                            
                        ListItem item = new ListItem(fvalue, selectedValue);
                        item.Selected = true;
                        this.ID_Tipo_Servicio.Items.Add(item);
                    }
                }
                catch
                {
                }

                    					
            }					
                        
        }
                
        // Event handler for ImageButton .
        public virtual void GasolineraXTipoGasolineraCopyButton_Click(object sender, ImageClickEventArgs args)
        {
        
            // The redirect URL is set on the Properties, Custom Properties or Actions.
            // The ModifyRedirectURL call resolves the parameters before the
            // Response.Redirect redirects the page to the URL.  
            // Any code after the Response.Redirect call will not be executed, since the page is
            // redirected to the URL.
            
          string url = @"../GasolineraXTipoGasolinera/AddGasolineraXTipoGasolinera.aspx?GasolineraXTipoGasolinera={PK}";
        
        bool shouldRedirect = true;
        string TargetKey = null;
        string DFKA = TargetKey;
        string id = DFKA;
        string value = id;
      
            try {
                // Enclose all database retrieval/update code within a Transaction boundary
                DbUtils.StartTransaction();
                
                url = this.ModifyRedirectUrl(url, "",false);
                url = this.Page.ModifyRedirectUrl(url, "",false);
              
            } catch (Exception ex) {
                  // Upon error, rollback the transaction
                  this.Page.RollBackTransaction(sender);
                  shouldRedirect = false;
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
                DbUtils.EndTransaction();
            }
            if (shouldRedirect) {
                this.Page.ShouldSaveControlsToSession = true;
                this.Page.Response.Redirect(url);
            }
        
            else if (TargetKey != null && !shouldRedirect){
            this.Page.ShouldSaveControlsToSession = true ; 
            this.Page.CloseWindow(true);
            }
        
        }
        
        // Event handler for ImageButton .
        public virtual void GasolineraXTipoGasolineraDeleteButton_Click(object sender, ImageClickEventArgs args)
        {
        
            try {
                // Enclose all database retrieval/update code within a Transaction boundary
                DbUtils.StartTransaction();
                
            if (!this.Page.IsPageRefresh) {
        
            if (this.GetRecord() == null){
            throw new Exception(Page.GetResourceValue("Err:NoRecSelected", "EnGasAdoAPP"));
            }
            this.Delete();
            // Setting the DataChanged to true results in the page being refreshed with
            // the most recent data from the database.  This happens in PreRender event
            // based on the current sort, search and filter criteria.
            this.DataChanged = true;
            this.ResetData = true;
          
            }
                this.Page.CommitTransaction(sender);
            } catch (Exception ex) {
                  // Upon error, rollback the transaction
                  this.Page.RollBackTransaction(sender);
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
                DbUtils.EndTransaction();
            }
    
        }
        
        // Event handler for ImageButton .
        public virtual void GasolineraXTipoGasolineraNewButton_Click(object sender, ImageClickEventArgs args)
        {
        
            // The redirect URL is set on the Properties, Custom Properties or Actions.
            // The ModifyRedirectURL call resolves the parameters before the
            // Response.Redirect redirects the page to the URL.  
            // Any code after the Response.Redirect call will not be executed, since the page is
            // redirected to the URL.
            
          string url = @"../GasolineraXTipoGasolinera/AddGasolineraXTipoGasolinera.aspx";
        
        bool shouldRedirect = true;
        string TargetKey = null;
        string DFKA = TargetKey;
        string id = DFKA;
        string value = id;
      
            try {
                // Enclose all database retrieval/update code within a Transaction boundary
                DbUtils.StartTransaction();
                
                url = this.ModifyRedirectUrl(url, "",false);
                url = this.Page.ModifyRedirectUrl(url, "",false);
              
            } catch (Exception ex) {
                  // Upon error, rollback the transaction
                  this.Page.RollBackTransaction(sender);
                  shouldRedirect = false;
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
                DbUtils.EndTransaction();
            }
            if (shouldRedirect) {
                this.Page.ShouldSaveControlsToSession = true;
                this.Page.Response.Redirect(url);
            }
        
            else if (TargetKey != null && !shouldRedirect){
            this.Page.ShouldSaveControlsToSession = true ; 
            this.Page.CloseWindow(true);
            }
        
        }
        
        // Event handler for ImageButton .
        public virtual void GasolineraXTipoGasolineraSaveButton_Click(object sender, ImageClickEventArgs args)
        {
        
            try {
                // Enclose all database retrieval/update code within a Transaction boundary
                DbUtils.StartTransaction();
                
        
              if (!this.Page.IsPageRefresh)
              {
                  this.SaveData();
              }

                    this.Page.CommitTransaction(sender);
            } catch (Exception ex) {
                  // Upon error, rollback the transaction
                  this.Page.RollBackTransaction(sender);
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
                DbUtils.EndTransaction();
            }
    
        }
        
        // event handler for Button with Layout
        public virtual void GasolineraXTipoGasolineraFilterButton_Click(object sender, EventArgs args)
        {
              
            try {
                
            this.DataChanged = true;
      
            } catch (Exception ex) {
                  this.Page.ErrorOnPage = true;

            // Report the error message to the end user
            BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
    
            } finally {
    
            }
    
        }
            
        protected virtual void ID_Gasolinera_SelectedIndexChanged(object sender, EventArgs args)
        {
            // If a large list selector or a Quick Add link is used, the dropdown list
            // will contain an item that was not in the original (smaller) list.  During postbacks,
            // this new item will not be in the list - since the list is based on the original values
            // read from the database. This function adds the value back if necessary.
            // In addition, This dropdown can be used on make/model/year style dropdowns.  Make filters the result of Model.
            // Mode filters the result of Year.  When users change the value of Make, Model and Year are repopulated.
            // When this function is fire for Make or Model, we don't want the following code executed.
            // Therefore, we check this situation using Items.Count > 1
            // Since both of these feature use javascript to fire this event, this can be skip if the event is fired by server side,
            // so we check if it is not postback
            if (!this.Page.IsPostBack && this.ID_Gasolinera.Items.Count > 1)
            {
                string selectedValue = MiscUtils.GetValueSelectedPageRequest(this.ID_Gasolinera);
                
            if (selectedValue != null &&
                selectedValue.Trim() != "" &&
                !MiscUtils.SetSelectedValue(this.ID_Gasolinera, selectedValue) &&
                !MiscUtils.SetSelectedDisplayText(this.ID_Gasolinera, selectedValue))
            {

                // construct a whereclause to query a record with Gasolinera.ID_Gasolinera = selectedValue
                    
                CompoundFilter filter2 = new CompoundFilter(CompoundFilter.CompoundingOperators.And_Operator, null);
                WhereClause whereClause2 = new WhereClause();
                filter2.AddFilter(new BaseClasses.Data.ColumnValueFilter(GasolineraTable.ID_Gasolinera, selectedValue, BaseClasses.Data.BaseFilter.ComparisonOperator.EqualsTo, false));
                whereClause2.AddFilter(filter2, CompoundFilter.CompoundingOperators.And_Operator);

                // Execute the query
                try
                {
                GasolineraRecord[] rc = GasolineraTable.GetRecords(whereClause2, new OrderBy(false, false), 0, 1);
                System.Collections.Generic.IDictionary<string, object> vars = new System.Collections.Generic.Dictionary<string, object> ();
                    // if find a record, add it to the dropdown and set it as selected item
                    if (rc != null && rc.Length == 1)
                    {
                        
                        string fvalue = GasolineraXTipoGasolineraTable.ID_Gasolinera.Format(selectedValue);																				
                            
                        ListItem item = new ListItem(fvalue, selectedValue);
                        item.Selected = true;
                        this.ID_Gasolinera.Items.Add(item);
                    }
                }
                catch
                {
                }

                    					
            }					
                        
            }
           						
        }
            
        protected virtual void ID_Tipo_Servicio_SelectedIndexChanged(object sender, EventArgs args)
        {
            // If a large list selector or a Quick Add link is used, the dropdown list
            // will contain an item that was not in the original (smaller) list.  During postbacks,
            // this new item will not be in the list - since the list is based on the original values
            // read from the database. This function adds the value back if necessary.
            // In addition, This dropdown can be used on make/model/year style dropdowns.  Make filters the result of Model.
            // Mode filters the result of Year.  When users change the value of Make, Model and Year are repopulated.
            // When this function is fire for Make or Model, we don't want the following code executed.
            // Therefore, we check this situation using Items.Count > 1
            // Since both of these feature use javascript to fire this event, this can be skip if the event is fired by server side,
            // so we check if it is not postback
            if (!this.Page.IsPostBack && this.ID_Tipo_Servicio.Items.Count > 1)
            {
                string selectedValue = MiscUtils.GetValueSelectedPageRequest(this.ID_Tipo_Servicio);
                
            if (selectedValue != null &&
                selectedValue.Trim() != "" &&
                !MiscUtils.SetSelectedValue(this.ID_Tipo_Servicio, selectedValue) &&
                !MiscUtils.SetSelectedDisplayText(this.ID_Tipo_Servicio, selectedValue))
            {

                // construct a whereclause to query a record with Tipo_Servicio.ID_Tipo_Servicio = selectedValue
                    
                CompoundFilter filter2 = new CompoundFilter(CompoundFilter.CompoundingOperators.And_Operator, null);
                WhereClause whereClause2 = new WhereClause();
                filter2.AddFilter(new BaseClasses.Data.ColumnValueFilter(Tipo_ServicioTable.ID_Tipo_Servicio, selectedValue, BaseClasses.Data.BaseFilter.ComparisonOperator.EqualsTo, false));
                whereClause2.AddFilter(filter2, CompoundFilter.CompoundingOperators.And_Operator);

                // Execute the query
                try
                {
                Tipo_ServicioRecord[] rc = Tipo_ServicioTable.GetRecords(whereClause2, new OrderBy(false, false), 0, 1);
                System.Collections.Generic.IDictionary<string, object> vars = new System.Collections.Generic.Dictionary<string, object> ();
                    // if find a record, add it to the dropdown and set it as selected item
                    if (rc != null && rc.Length == 1)
                    {
                        
                        string fvalue = GasolineraXTipoGasolineraTable.ID_Tipo_Servicio.Format(selectedValue);																				
                            
                        ListItem item = new ListItem(fvalue, selectedValue);
                        item.Selected = true;
                        this.ID_Tipo_Servicio.Items.Add(item);
                    }
                }
                catch
                {
                }

                    					
            }					
                        
            }
           						
        }
            
  
        private Hashtable _PreviousUIData = new Hashtable();
        public virtual Hashtable PreviousUIData {
            get {
                return this._PreviousUIData;
            }
            set {
                this._PreviousUIData = value;
            }
        }
  
        private bool _IsNewRecord = true;
        public virtual bool IsNewRecord {
            get {
                return this._IsNewRecord;
            }
            set {
                this._IsNewRecord = value;
            }
        }

        private bool _DataChanged = false;
        public virtual bool DataChanged {
            get {
                return this._DataChanged;
            }
            set {
                this._DataChanged = value;
            }
        }

        private bool _ResetData = false;
        public virtual bool ResetData {
            get {
                return (this._ResetData);
            }
            set {
                this._ResetData = value;
            }
        }
        
        public String RecordUniqueId {
            get {
                return (string)this.ViewState["BaseGasolineraXTipoGasolineraRecordControl_Rec"];
            }
            set {
                this.ViewState["BaseGasolineraXTipoGasolineraRecordControl_Rec"] = value;
            }
        }
        
        private GasolineraXTipoGasolineraRecord _DataSource;
        public GasolineraXTipoGasolineraRecord DataSource {
             
            get {
                return (this._DataSource);
            }
            set {
                this._DataSource = value;
            }
        }
        
        

        private string _checkSum;
        public virtual string CheckSum {
            get {
                return (this._checkSum);
            }
            set {
                this._checkSum = value;
            }
        }
    
        private int _TotalPages;
        public virtual int TotalPages {
            get {
                return (this._TotalPages);
            }
            set {
                this._TotalPages = value;
            }
        }
        
        private int _PageIndex;
        public virtual int PageIndex {
            get {
                return (this._PageIndex);
            }
            set {
                this._PageIndex = value;
            }
        }
        
        private int _PageSize;
        public int PageSize {
          get {
            return this._PageSize;
          }
          set {
            this._PageSize = value;
          }
        }
      
        private int _TotalRecords;
        public int TotalRecords {
          get {
            return (this._TotalRecords);
          }
          set {
            if (this.PageSize > 0) {
              this.TotalPages = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(value) / Convert.ToDouble(this.PageSize)));
            }
            this._TotalRecords = value;
          }
        }
        
        private bool _DisplayLastPage;
        public virtual bool DisplayLastPage {
            get {
                return (this._DisplayLastPage);
            }
            set {
                this._DisplayLastPage = value;
            }
        }
        
        
        private OrderBy _CurrentSortOrder = null;
        public OrderBy CurrentSortOrder {
            get {
                return this._CurrentSortOrder;
            }
            set {
                this._CurrentSortOrder = value;
            }
        }
          
    
        private KeyValue selectedParentKeyValue;
        public KeyValue SelectedParentKeyValue
        {
            get
            {
                return this.selectedParentKeyValue;
            }
            set
            {
                this.selectedParentKeyValue = value;
            }
        }
       
#region "Helper Properties"
        
        public System.Web.UI.WebControls.ImageButton GasolineraXTipoGasolineraCopyButton {
            get {
                return (System.Web.UI.WebControls.ImageButton)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "GasolineraXTipoGasolineraCopyButton");
            }
        }
        
        public System.Web.UI.WebControls.ImageButton GasolineraXTipoGasolineraDeleteButton {
            get {
                return (System.Web.UI.WebControls.ImageButton)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "GasolineraXTipoGasolineraDeleteButton");
            }
        }
        
        public EnGasAdoAPP.UI.IThemeButton GasolineraXTipoGasolineraFilterButton {
            get {
                return (EnGasAdoAPP.UI.IThemeButton)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "GasolineraXTipoGasolineraFilterButton");
            }
        }
        
        public System.Web.UI.WebControls.ImageButton GasolineraXTipoGasolineraNewButton {
            get {
                return (System.Web.UI.WebControls.ImageButton)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "GasolineraXTipoGasolineraNewButton");
            }
        }
        
        public EnGasAdoAPP.UI.IPaginationShort GasolineraXTipoGasolineraPagination {
            get {
                return (EnGasAdoAPP.UI.IPaginationShort)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "GasolineraXTipoGasolineraPagination");
            }
        }
        
        public System.Web.UI.WebControls.ImageButton GasolineraXTipoGasolineraSaveButton {
            get {
                return (System.Web.UI.WebControls.ImageButton)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "GasolineraXTipoGasolineraSaveButton");
            }
        }
        
        public System.Web.UI.WebControls.Literal GasolineraXTipoGasolineraTitle {
            get {
                return (System.Web.UI.WebControls.Literal)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "GasolineraXTipoGasolineraTitle");
            }
        }
        
        public System.Web.UI.WebControls.DropDownList ID_Gasolinera {
            get {
                return (System.Web.UI.WebControls.DropDownList)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "ID_Gasolinera");
            }
        }
            
        public System.Web.UI.WebControls.ImageButton ID_GasolineraAddRecordLink {
            get {
                return (System.Web.UI.WebControls.ImageButton)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "ID_GasolineraAddRecordLink");
            }
        }
        
        public System.Web.UI.WebControls.ListBox ID_GasolineraFilter {
            get {
                return (System.Web.UI.WebControls.ListBox)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "ID_GasolineraFilter");
            }
        }
        
        public System.Web.UI.WebControls.Literal ID_GasolineraLabel {
            get {
                return (System.Web.UI.WebControls.Literal)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "ID_GasolineraLabel");
            }
        }
        
        public System.Web.UI.WebControls.Literal ID_GasolineraLabel1 {
            get {
                return (System.Web.UI.WebControls.Literal)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "ID_GasolineraLabel1");
            }
        }
        
        public System.Web.UI.WebControls.DropDownList ID_Tipo_Servicio {
            get {
                return (System.Web.UI.WebControls.DropDownList)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "ID_Tipo_Servicio");
            }
        }
            
        public System.Web.UI.WebControls.ImageButton ID_Tipo_ServicioAddRecordLink {
            get {
                return (System.Web.UI.WebControls.ImageButton)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "ID_Tipo_ServicioAddRecordLink");
            }
        }
        
        public System.Web.UI.WebControls.ListBox ID_Tipo_ServicioFilter {
            get {
                return (System.Web.UI.WebControls.ListBox)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "ID_Tipo_ServicioFilter");
            }
        }
        
        public System.Web.UI.WebControls.Literal ID_Tipo_ServicioLabel {
            get {
                return (System.Web.UI.WebControls.Literal)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "ID_Tipo_ServicioLabel");
            }
        }
        
        public System.Web.UI.WebControls.Literal ID_Tipo_ServicioLabel1 {
            get {
                return (System.Web.UI.WebControls.Literal)BaseClasses.Utils.MiscUtils.FindControlRecursively(this, "ID_Tipo_ServicioLabel1");
            }
        }
        
#endregion

#region "Helper Functions"
        public override string ModifyRedirectUrl(string url, string arg, bool bEncrypt)
        {
            return this.Page.EvaluateExpressions(url, arg, bEncrypt, this);
        }

        public override string EvaluateExpressions(string url, string arg, bool bEncrypt)
        {
        GasolineraXTipoGasolineraRecord rec = null;
             
            try {
                rec = this.GetRecord();
            }
            catch (Exception ) {
                // Do Nothing
            }
            
            if (rec == null && url.IndexOf("{") >= 0) {
                // Localization.
                
                throw new Exception(Page.GetResourceValue("Err:NoRecSelected", "EnGasAdoAPP"));
                    
            }
        
            return EvaluateExpressions(url, arg, rec, bEncrypt);
             
        }

        
        public virtual GasolineraXTipoGasolineraRecord GetRecord()
             
        {
        
            if (this.DataSource != null) {
                return this.DataSource;
            }
            
            if (this.RecordUniqueId != null) {
              
                return GasolineraXTipoGasolineraTable.GetRecord(this.RecordUniqueId, true);
              
            }
            
            // Localization.
            
            return null;
                
        }

        public new BaseApplicationPage Page
        {
            get {
                return ((BaseApplicationPage)base.Page);
            }
        }

#endregion

}

  

#endregion
    
  
}

  